using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Model.StateCommands;
using Headspring.Training.Domain.Services;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace Headspring.Training.Domain.UnitTests.Model
{
  [TestFixture]
  public class NotificationFactoryTester
  {
    [Test]
    public void CreateWorkingNotification()
    {
      WorkOrder firstWO = new WorkOrder();
      firstWO.Status = WorkOrderStatus.Cancelled;
      Employee darren = new Employee();
      darren.EmailAddress = "darrendave@gmail.com";
      darren.FirstName = "Darren";
      darren.LastName = "Dave";
      darren.SetAllNotificationPreferencesTo(NotificationType.Both);
      firstWO.Assignee = darren;
      firstWO.Creator = darren;

      INotificationFactory notificationFactory = new NotificationFactory();
      WorkOrderNotification notification1 = notificationFactory.CreateNotification(new InProgressToCancelledCommand(firstWO, darren), firstWO);

      Assert.AreEqual(notification1.PreviousStatus, WorkOrderStatus.InProgress);
    }

    [Test]
    public void CreateBrokenNotification()
    {
      WorkOrder firstWO = new WorkOrder();
      firstWO.Status = WorkOrderStatus.Cancelled;
      Employee darren = new Employee();
      darren.EmailAddress = "darrendave@gmail.com";
      darren.FirstName = "Darren";
      darren.LastName = "Dave";
      darren.SetAllNotificationPreferencesTo(NotificationType.Both);
      firstWO.Assignee = darren;
      firstWO.Creator = darren;

      INotificationFactory notificationFactory = new NotificationFactory();
      WorkOrderNotification notification1 = notificationFactory.CreateNotification(new InProgressToCancelledCommand(firstWO, darren), firstWO);

      Assert.AreNotEqual(notification1.PreviousStatus, WorkOrderStatus.Complete);
    }

    [Test]
    public void TestWorkingTransitionalStates()
    {
      Employee darren = new Employee();
      darren.EmailAddress = "darrendave@gmail.com";
      darren.FirstName = "Darren";
      darren.LastName = "Dave";
      darren.SetAllNotificationPreferencesTo(NotificationType.Both);

      Employee lam = new Employee();
      lam.EmailAddress = "lamchakchan@gmail.com";
      lam.FirstName = "Lam";
      lam.LastName = "Chan";
      lam.SetAllNotificationPreferencesTo(NotificationType.Both);



      //
      WorkOrder firstWO1 = new WorkOrder();
      firstWO1.Assignee = darren;
      firstWO1.Status = WorkOrderStatus.Cancelled;
      firstWO1.Creator = lam;

      INotificationFactory notificationFactory1 = new NotificationFactory();
      WorkOrderNotification notification11 = notificationFactory1.CreateNotification(new InProgressToCancelledCommand(firstWO1, darren), firstWO1);

      Assert.AreEqual(notification11.PreviousStatus, WorkOrderStatus.InProgress);
      Assert.That(notification11.Recipient, Is.EqualTo(darren));
      Assert.That(notification11.From, Is.EqualTo(lam));

      WorkOrder firstWO2 = new WorkOrder();
      firstWO2.Assignee = darren;
      firstWO2.Status = WorkOrderStatus.Complete;
      firstWO2.Creator = lam;

      INotificationFactory notificationFactory2 = new NotificationFactory();
      WorkOrderNotification notification12 = notificationFactory2.CreateNotification(new InProgressToCompleteCommand(firstWO2, darren), firstWO2);

      Assert.AreEqual(notification12.PreviousStatus, WorkOrderStatus.InProgress);
      Assert.That(notification12.Recipient, Is.EqualTo(lam));
      Assert.That(notification12.From, Is.EqualTo(darren));

      WorkOrder firstWO3 = new WorkOrder();
      firstWO3.Assignee = darren;
      firstWO3.Status = WorkOrderStatus.Assigned;
      firstWO3.Creator = lam;

      INotificationFactory notificationFactory3 = new NotificationFactory();
      WorkOrderNotification notification13 = notificationFactory3.CreateNotification(new CompleteToAssignedCommand(firstWO3, darren), firstWO3);

      Assert.AreEqual(notification13.PreviousStatus, WorkOrderStatus.Complete);
      Assert.That(notification13.Recipient, Is.EqualTo(darren));
      Assert.That(notification13.From, Is.EqualTo(lam));
    }

    [Test]
    public void TestNonWorkingTransitionalStates()
    {
      WorkOrder firstWO1 = new WorkOrder();
      firstWO1.Status = WorkOrderStatus.Assigned;

      INotificationFactory notificationFactory1 = new NotificationFactory();
      WorkOrderNotification notification11 = notificationFactory1.CreateNotification(new DraftToAssignedCommand(firstWO1, new Employee()), firstWO1);

      Assert.AreEqual(notification11, null);

      WorkOrder firstWO2 = new WorkOrder();
      firstWO2.Status = WorkOrderStatus.Cancelled;

      INotificationFactory notificationFactory2 = new NotificationFactory();
      WorkOrderNotification notification12 = notificationFactory2.CreateNotification(new AssignedToCancelledCommand(firstWO2, new Employee()), firstWO2);

      Assert.AreEqual(notification12, null);

      WorkOrder firstWO3 = new WorkOrder();
      firstWO3.Status = WorkOrderStatus.InProgress;

      INotificationFactory notificationFactory3 = new NotificationFactory();
      WorkOrderNotification notification13 = notificationFactory3.CreateNotification(new AssignedToInProgressCommand(firstWO3, new Employee()), firstWO3);

      Assert.AreEqual(notification13, null);
    }
  }
}